Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Cuando se usa "y" en rubí, la tierra es plana

Como siempre me han enseñado en lógica, el operador "y" significa que ambos valores deben ser verdaderos, para que la declaración completa sea verdadera. Si tiene muchas declaraciones encadenadas con "y", entonces si cualquiera de ellas es falsa, debería hacer que toda la afirmación sea falsa. En Ruby, sin embargo, me encontré con este escenario:

 horizon_flat = true one_up_and_down = true magellan_fell = false flat_earth_thesis = horizon_flat and one_up_and_down and magellan_fell puts("Hey ruby, doesn't the horizon look flat?") puts(horizon_flat) # true puts("Isn't there only one up and one down?") puts(one_up_and_down) # true puts("Did Magellan fall off the earth?") puts(magellan_fell) # false puts("Is the earth flat?") puts(flat_earth_thesis) # true

Extrañamente, si solo ejecuto la declaración en sí, devuelve false puts(horizon_flat and one_up_and_down and magellan_fell) # false

Pero si almaceno esa declaración en una variable y luego la llamo, la variable da como resultado verdadero. ¿Por qué Ruby piensa que la tierra es plana?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Mientras esperas esto:

 flat_earth_thesis = horizon_flat and one_up_and_down and magellan_fell

Para ser evaluado como:

 flat_earth_thesis = (horizon_flat and one_up_and_down and magellan_fell)

En cambio, se evalúa como:

 (flat_earth_thesis = horizon_flat) and one_up_and_down and magellan_fell

Como se indica en los comentarios, revise la precedencia del operador .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!